<?php
error_reporting(0);

include_once "../ps-includes/itransportation-inc.php";
include_once "../ps-includes/iconverter-inc.php";

/*-- Test Upload -----------------------------------------------*/
$hostname = "ftp.ccinteg.com";
$username = "gdsdev@ccinteg.com";
$password = "gdsftpdev";

//echo "TestMODE: $testMode";
$testMode = $_GET["testMode"];
if ($testMode=="Up") {
	$ftp = new FTP($hostname, $username, $password, FTP::ProtocolTYPE_FTP, FTP::PassiveMODE_ON);
	if ($ftp->Connect()) {
		if ($ftp->Send("/var/www/gdssmprocdev/ps_xml/", "gds_20080402_123906_itemsku.xml", "", "", FTP::TransportTYPE_BINARY)) {
			echo "Upload is successful.";
		}
		else 
			echo $ftp->ErrorMessage();
		$ftp->Disconnect();
	} else {
		echo $ftp->ErrorMessage();
	}
}
/* Test Download -----------------------------------------------*/
if ($testMode=="Down") {
	$ftp = new FTP($hostname, $username, $password, FTP::ProtocolTYPE_FTP, FTP::PassiveMODE_ON);
	if ($ftp->Connect()) {
		if ($ftp->Receive("", "xmltest.xml", "../ps_xml/", "xmltestDown.xml", FTP::TransportTYPE_BINARY))
			echo "Download is successful.";
		else 
			echo $ftp->ErrorMessage();
		$ftp->Disconnect();
	} else {
		echo $ftp->ErrorMessage();
	}
}
/* Test Convert Array to XML -----------------------------------------------*/
if ($testMode=="Arr2Xml") {
	$test = array(
				 "Root"=>
						array(
								"Header"=>array("H1"=>"H1 value"), 
							  	"Item"=>array(
												"Field0"=>"Field0's value",
												"Field1"=>"Field1's value",
												"Field2"=>"Field2's value"
											 )
							 )
				 );
	
	$convert = new ConvertData(ConvertData::ConvertTYPE_ARRAY2XML);
	
	if ($convert->Convert($test, "../ps_xml/xmltest.xml", "", "UTF-8"))
		echo "Convert Successful!";
	else
		echo $convert->ErrorMessage();
}	

/* Test Convert XML to Array -----------------------------------------------*/
if ($testMode=="Xml2Arr") {
	$convert = new ConvertData(ConvertData::ConvertTYPE_XML2ARRAY);
	
	if ($convert->Convert($test, "../ps_xml/xmltest.xml")) {
		echo "Convert Successful!<br>";
		echo "<pre>";
		print_r($test);
		echo "</pre>";
	}
	else
		echo $convert->ErrorMessage();
}
?>